# C:/Python27/TextResuming/html_parser.py
# parsing html
# Author : @ismailsunni

from HTMLParser import HTMLParser

class MLStripper(HTMLParser):
	'''Class for striping html tag'''

	def __init__(self):
		self.reset()
		self.fed = []

	def handle_data(self, d):
		self.fed.append(d)

	def get_data(self):
		return ''.join(self.fed)

	def insert_newline(self):
		pass

def strip_tags(html, replace_newline = False):
	'''Function for removing html tag.
		if replace_newline = true, replace <p>, </p>, </br>, <br>, <br/> with \\n.
		
		@parameters
		@html = html text
		@replace_newline = boolean for new line'''
	
	if replace_newline == True:
		html = html.replace('<p>', '\n<p>')	
		html = html.replace('</p>', '\n</p>')
		html = html.replace('<br>', '\n<br>')
		html = html.replace('</br>', '\n</br>')	
		html = html.replace('<br/>', '\n<br/>')	
	
	s = MLStripper()
	s.feed(html)
	return s.get_data()

# main function for testing
def main():
	html = '<p>aha</br>ha<p>'
	print strip_tags(html, True)

if __name__ == '__main__':
	main()

		